Imports System.Windows.Forms

Public Class dlgDetailReport
    Public EmployeeID As String
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Report.StartDate = New Date(dtpFrom.Value.Year, dtpFrom.Value.Month, dtpFrom.Value.Day, 0, 0, 0)
        Report.EndDate = New Date(dtpTo.Value.Year, dtpTo.Value.Month, dtpTo.Value.Day, 23, 59, 59)

        'Report.couponlimit = nupCoupon.Value
        'Me.DialogResult = System.Windows.Forms.DialogResult.OK
        'Me.Close()
        Report.RType = "DETAIL"
        Report.EmployeeID = EmployeeID
        Report.ShowDialog()


    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub


    Private Sub dlgDetailReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dtpFrom.Value = New Date(Year(Now()), Month(Now()), 1)
        dtpTo.Value = DateAdd(DateInterval.Day, -1, New Date(Year(DateAdd(DateInterval.Month, 1, Now())), Month(DateAdd(DateInterval.Month, 1, Now())), 1))

        'ChinhLH correct
        'dtpTo.Value = DateAdd(DateInterval.Day, -1, New Date(Year(Now()), Month(Now()) + 1, 1))
        dtpTo.Value = DateAdd(DateInterval.Day, -1, New Date(Year(DateAdd(DateInterval.Month, 1, Now())), Month(DateAdd(DateInterval.Month, 1, Now())), 1))
    End Sub

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Dim f As New POSPrinter.U220POS
        Dim dt As DataTable
        'Dim st As String
        Dim _Color As Byte = getOptions("color")
        Dim _Port As String = getOptions("port")
        Dim _Header As String = getOptions("header")

        dt = db.getDetailReport(New Date(dtpFrom.Value.Year, dtpFrom.Value.Month, dtpFrom.Value.Day, 0, 0, 0), New Date(dtpTo.Value.Year, dtpTo.Value.Month, dtpTo.Value.Day, 23, 59, 59), EmployeeID).Tables(0)
        
        
        f.openPrinter(_Port) 'db.getvalue("select * from options where oname = 'Port'", "ovalue")




        'st = ""
        'st = st & _Header & Chr(13) & Chr(10)
        'st = st & "Name: " & dt.Rows(0).Item("eFullName") & Chr(13) & Chr(10)
        'st = st & "Dept: " & dt.Rows(0).Item("Dep_Name") & Chr(13) & Chr(10)
        'st = st & "        Date             Coupon " & Chr(13) & Chr(10)
        'For i As Integer = 0 To dt.Rows.Count - 1
        '    st = st & Format(dt.Rows(i).Item("tDate"), "dd-MMM-yyyy hh:mm:ss") & "    " & dt.Rows(i).Item("coupon") & Chr(13) & Chr(10)
        'Next
        'st = st & "               Total     " & dt.Rows(0).Item("total")





        f.WriteString(_Header & Chr(13) & Chr(10), 0, 1, 1, _Color)
        f.WriteString("Name: " & dt.Rows(0).Item("eFullName"), 1, 0, 0, _Color)
        f.WriteString("Dept: " & dt.Rows(0).Item("Dep_Name") & Chr(13) & Chr(10), 1, 0, 0, _Color)
        f.WriteString("        Date            Coupon", 1, 1, 0, _Color)
        For i As Integer = 0 To dt.Rows.Count - 1
            f.WriteString(Format(dt.Rows(i).Item("tDate"), "dd-MMM-yyyy hh:mm:ss") & "    " & dt.Rows(i).Item("coupon"), 1, 0, 0, FrTransactions._Color)
        Next
        f.WriteString("               Total     " & dt.Rows(0).Item("total"), 1, 1, 0, FrTransactions._Color)

        f.closePrinter()

    End Sub
End Class
